<template>
	<view class="page-fade-in" :style="{opacity: pageOpc}">
		<template v-if="pageOpc">
			<view class="content">
				<view class="shop-info-box">
					<view class="lable-item" v-for="(item,index) in lableArr" :key='index'>
						<image src="/static/user/close.png" class="close-btn" @tap="delLable(index)"></image>
						<view class="info-item flexWrapNo">
							<view class="item-title">
								优惠标签{{Number(index+1)}}:
							</view>
							<input placeholder="请输入标签" placeholder-class="placeholderClass" v-model="lableArr[index]"/>
						</view>
					</view>
					<view class="remaks-box">
						用户在该店间可享受的特殊优惠。可添加多个标签，但多个标签不允许重复。
					</view>
				</view>
				<view class="determine-btn" @tap="addlable">+添加优惠标签</view>
				<view class="bottom-box flexWrapNo">
					<view class="define-btn" @tap="setStoreInfo()">确定</view>
				</view>
			</view>
		</template>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				pageOpc: 0,
				lableArr: [""]
			}
		},
		onLoad(ops) {
			this.getStoreInfo();
		},
		onReady() {
			setTimeout(() => {
				this.pageOpc = 1
			}, 100)
		},
		methods: {
			addlable() {
				let item =""
				this.lableArr.push(item)
			},
			delLable(index) {
				this.lableArr.splice(index, 1)
			},
			getStoreInfo(){
				this.$request.post(this.$api.storeInfo, {
					store_id:uni.getStorageSync('store_id')
				}, {
					token:true
				}).then(res => {
					let {
						data = {}
					} = res;
					if (res.code==1) {
						this.lableArr=data.label_txt?data.label_txt.split(','):[]
					}
				})
			},
			setStoreInfo(){
				let pages = getCurrentPages(); //当前页
				let beforePage = pages[pages.length - 2]; //上个页面
				beforePage.$vm.label_txt=this.lableArr.join(',')
				beforePage.$vm.setStoreInfo()
				setTimeout(()=>{
					uni.navigateBack({delta:1})
				},1000)
			}
		}
	}
</script>

<style lang="scss">
	.content {
		padding: 0 36upx;
		padding-bottom: 120upx;

		.shop-info-box {
			.info-item {
				font-size: 28upx;
				font-family: PingFang SC;
				font-weight: 400;
				line-height: 40upx;
				color: #FFFFFF;
				padding: 30upx 0;
				border-bottom: 1upx solid #36355E;

				picker {
					flex: none;
				}

				.item-title {
					margin-right: 32upx;
					flex: none;
				}

				.small {
					font-size: 28rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #FFFFFF;
					margin: 0 40upx;
				}

				.select-input {
					font-size: 28rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #FFE577;
					flex: 1;
				}

				input {
					font-size: 28rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #FFE577;
					flex: 1;
				}
				.icon-more {
					border-color: #FFFFFF;
				}

				.placeholderclass {
					font-size: 28rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #FFE577;
				}
			}

			.remaks-box {
				font-size: 28rpx;
				font-family: PingFang SC-Regular, PingFang SC;
				font-weight: 400;
				color: #82819B;
				line-height: 40rpx;
				padding-left: 158upx;
				margin-top: 12upx;
			}
		}

		.determine-btn {
			font-size: 32rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 500;
			color: #FFFFFF;
			width: 322rpx;
			height: 80rpx;
			line-height: 80rpx;
			text-align: center;
			background: #26BCFD;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			margin: 78upx auto;
		}

		.bottom-box {
			height: 120rpx;
			background: #1D1C5C;
			position: fixed;
			left: 0;
			right: 0;
			bottom: 0;
			margin: auto;
			justify-content: center;
			font-size: 32rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 500;
			color: #FFFFFF;

			.define-btn {
				font-size: 32rpx;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 500;
				color: #FFFFFF;
				line-height: 80rpx;
				width: 322rpx;
				height: 80rpx;
				background: #26BCFD;
				border-radius: 16rpx 16rpx 16rpx 16rpx;
				text-align: center;
			}
		}

		.lable-item {
			padding-top: 40upx;
			position: relative;

			.close-btn {
				width: 40upx;
				height: 40upx;
				position: absolute;
				top: 20upx;
				right: 0;
			}
		}
	}
</style>